package Conexiones;


//PLANTILLA CONEXION MYSQL

import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;



public class ConexionMySQL{
        private Connection connection;
	private String driverName = "com.mysql.jdbc.Driver";
	private String sourceURL = "jdbc:mysql://localhost:3306/";
	private String user = "root";
	private String password = "";

//ingrese nombre base de datos y usuario con su contraseña
	public ConexionMySQL(String nombreBaseDatos,String user,String contrase) {
        try {
            Class.forName(driverName);
            this.user=user;
            this.password=contrase;
            this.sourceURL=this.sourceURL+nombreBaseDatos;
            connection = DriverManager.getConnection(this.sourceURL, this.user, this.password);
        } catch (SQLException ex) {
            Logger.getLogger(ConexionMySQL.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(ConexionMySQL.class.getName()).log(Level.SEVERE, null, ex);
        }
           
                
	}

	public void cerrar() throws SQLException {

		connection.close();
	}

	

	public Connection getConnection() {
		return connection;
	}

	public void setConnection(Connection connection) {
		this.connection = connection;
	}
 
}

    
   
  

